﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using nERP.Model.Wms;
using nERP.Model;
using nERP.Model.Po;
using nERP.Model.Bas;

namespace nERP.ViewModel.Wms.BuyReturnOutWarehouseDetailVMs
{
    public partial class BuyReturnOutWarehouseDetailListVM : BasePagedListVM<BuyReturnOutWarehouseDetail_View, BuyReturnOutWarehouseDetailSearcher>
    {

        protected override IEnumerable<IGridColumn<BuyReturnOutWarehouseDetail_View>> InitGridHeader()
        {
            return new List<GridColumn<BuyReturnOutWarehouseDetail_View>>{

                this.MakeGridHeader(x => x.BuyReturnOutWarehouseDetail_Seq).SetTitle(@Localizer["Page.序号"].Value),
                this.MakeGridHeader(x => x.BuyReturnOutWarehouseDetail_BuyReturn).SetTitle(@Localizer["Page.采购退货"].Value),
                this.MakeGridHeader(x => x.BuyReturnOutWarehouseDetail_BuyReturnOutWarehouse).SetTitle(@Localizer["Page.采购退货出库"].Value),
                this.MakeGridHeader(x => x.BuyReturnOutWarehouseDetail_Buy).SetTitle(@Localizer["Page.采购订单"].Value),
                this.MakeGridHeader(x => x.BuyReturnOutWarehouseDetail_BuyReturnOutWarehouseDetailCode).SetTitle(@Localizer["Page.采购退货出库明细单号"].Value),
                this.MakeGridHeader(x => x.BuyReturnOutWarehouseDetail_BuyDetail).SetTitle(@Localizer["Page.采购明细"].Value),
                this.MakeGridHeader(x => x.BuyReturnOutWarehouseDetail_Warehouse).SetTitle(@Localizer["Page.仓库"].Value),
                this.MakeGridHeader(x => x.BuyReturnOutWarehouseDetail_Goods).SetTitle(@Localizer["Page.商品"].Value),
                this.MakeGridHeader(x => x.BuyReturnOutWarehouseDetail_GoodsName).SetTitle(@Localizer["Page.商品名称"].Value),
                this.MakeGridHeader(x => x.BuyReturnOutWarehouseDetail_GoodsSpec).SetTitle(@Localizer["Page.商品规格"].Value),
                this.MakeGridHeader(x => x.BuyReturnOutWarehouseDetail_GoodsUnit).SetTitle(@Localizer["Page.计量单位"].Value),
                this.MakeGridHeader(x => x.BuyReturnOutWarehouseDetail_ReturnNumber).SetTitle(@Localizer["Page.退货出库数量"].Value),
                this.MakeGridHeader(x => x.BuyReturnOutWarehouseDetail_Remark).SetTitle(@Localizer["_Admin.Remark"].Value),
                this.MakeGridHeader(x => x.BuyReturnOutWarehouseDetail_Status).SetTitle(@Localizer["Page.状态"].Value),
                this.MakeGridHeader(x => x.BuyReturnOutWarehouseDetail_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.BuyReturnOutWarehouseDetail_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.BuyReturnOutWarehouseDetail_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.BuyReturnOutWarehouseDetail_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }


        public override IOrderedQueryable<BuyReturnOutWarehouseDetail_View> GetSearchQuery()
        {
            var query = DC.Set<BuyReturnOutWarehouseDetail>()

                .CheckEqual(Searcher.Seq, x => x.Seq)
                .CheckEqual(Searcher.BuyReturnId, x => x.BuyReturnId)
                .CheckEqual(Searcher.BuyReturnOutWarehouseId, x => x.BuyReturnOutWarehouseId)
                .CheckEqual(Searcher.BuyId, x => x.BuyId)
                .CheckContain(Searcher.BuyReturnOutWarehouseDetailCode, x => x.BuyReturnOutWarehouseDetailCode)
                .CheckEqual(Searcher.BuyDetailId, x => x.BuyDetailId)
                .CheckEqual(Searcher.WarehouseId, x => x.WarehouseId)
                .CheckEqual(Searcher.GoodsId, x => x.GoodsId)
                .CheckContain(Searcher.GoodsName, x => x.GoodsName)
                .CheckContain(Searcher.GoodsSpec, x => x.GoodsSpec)
                .CheckContain(Searcher.GoodsUnit, x => x.GoodsUnit)
                .CheckEqual(Searcher.ReturnNumber, x => x.ReturnNumber)
                .CheckContain(Searcher.Remark, x => x.Remark)
                .CheckEqual(Searcher.Status, x => x.Status)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x => x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x => x.UpdateBy)
                .Select(x => new BuyReturnOutWarehouseDetail_View
                {
                    ID = x.ID,

                    BuyReturnOutWarehouseDetail_Seq = x.Seq,
                    BuyReturnOutWarehouseDetail_BuyReturn = DC.Set<BuyReturn>().Where(z0 => z0.BuyReturnCode == x.BuyReturnId).Select(y => y.BuyReturnCode).FirstOrDefault(),
                    BuyReturnOutWarehouseDetail_BuyReturnOutWarehouse = DC.Set<BuyReturnOutWarehouse>().Where(z0 => z0.BuyReturnOutWarehouseCode == x.BuyReturnOutWarehouseId).Select(y => y.BuyReturnOutWarehouseCode).FirstOrDefault(),
                    BuyReturnOutWarehouseDetail_Buy = DC.Set<Buy>().Where(z0 => z0.BuyCode == x.BuyId).Select(y => y.BuyCode).FirstOrDefault(),
                    BuyReturnOutWarehouseDetail_BuyReturnOutWarehouseDetailCode = x.BuyReturnOutWarehouseDetailCode,
                    BuyReturnOutWarehouseDetail_BuyDetail = DC.Set<BuyDetail>().Where(z0 => z0.BuyDetailCode == x.BuyDetailId).Select(y => y.BuyDetailCode).FirstOrDefault(),
                    BuyReturnOutWarehouseDetail_Warehouse = DC.Set<Warehouse>().Where(z0 => z0.WarehouseCode == x.WarehouseId).Select(y => y.WarehouseName).FirstOrDefault(),
                    BuyReturnOutWarehouseDetail_Goods = x.GoodsId,// DC.Set<Goods>().Where(z0 => z0.GoodsCode == x.GoodsId).Select(y => y.GoodsName).FirstOrDefault(),
                    BuyReturnOutWarehouseDetail_GoodsName = x.GoodsName,
                    BuyReturnOutWarehouseDetail_GoodsSpec = x.GoodsSpec,
                    BuyReturnOutWarehouseDetail_GoodsUnit = x.GoodsUnit,
                    BuyReturnOutWarehouseDetail_ReturnNumber = x.ReturnNumber,
                    BuyReturnOutWarehouseDetail_Remark = x.Remark,
                    BuyReturnOutWarehouseDetail_Status = x.Status,
                    BuyReturnOutWarehouseDetail_CreateTime = x.CreateTime,
                    BuyReturnOutWarehouseDetail_UpdateTime = x.UpdateTime,
                    BuyReturnOutWarehouseDetail_CreateBy = x.CreateBy,
                    BuyReturnOutWarehouseDetail_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }


    }
    public class BuyReturnOutWarehouseDetail_View : BuyReturnOutWarehouseDetail
    {

        public int? BuyReturnOutWarehouseDetail_Seq { get; set; }
        public string BuyReturnOutWarehouseDetail_BuyReturn { get; set; }
        public string BuyReturnOutWarehouseDetail_BuyReturnOutWarehouse { get; set; }
        public string BuyReturnOutWarehouseDetail_Buy { get; set; }
        public string BuyReturnOutWarehouseDetail_BuyReturnOutWarehouseDetailCode { get; set; }
        public string BuyReturnOutWarehouseDetail_BuyDetail { get; set; }
        public string BuyReturnOutWarehouseDetail_Warehouse { get; set; }
        public string BuyReturnOutWarehouseDetail_Goods { get; set; }
        public string BuyReturnOutWarehouseDetail_GoodsName { get; set; }
        public string BuyReturnOutWarehouseDetail_GoodsSpec { get; set; }
        public string BuyReturnOutWarehouseDetail_GoodsUnit { get; set; }
        public decimal? BuyReturnOutWarehouseDetail_ReturnNumber { get; set; }
        public string BuyReturnOutWarehouseDetail_Remark { get; set; }
        public dStatusTypeEnum? BuyReturnOutWarehouseDetail_Status { get; set; }
        public DateTime? BuyReturnOutWarehouseDetail_CreateTime { get; set; }
        public DateTime? BuyReturnOutWarehouseDetail_UpdateTime { get; set; }
        public string BuyReturnOutWarehouseDetail_CreateBy { get; set; }
        public string BuyReturnOutWarehouseDetail_UpdateBy { get; set; }

    }

}